<template>
  <slot v-if="hasPermission" />
</template>

<script setup>
import { usePermissionStore } from '@/store/permission'

const props = defineProps({
  path: {
    type: String,
    default: '',
  },
  action: {
    type: String,
    default: '',
  },
})

const { judgeMenuPermission, judgeActionPermission } = usePermissionStore()

const hasPermission = computed(() => {
  if (props.path) {
    return judgeMenuPermission(props.path)
  } else if (props.action) {
    if (props.action.includes(',')) {
      const actions = props.action.split(',')
      return actions.some((action) => judgeActionPermission(action))
    } else {
      return judgeActionPermission(props.action)
    }
  }
  return false
})

onMounted(() => {
  // judgeMenuPermission() // 判断是否有权限
})
</script>
